<template>
  <a-breadcrumb style="font-size: 18px; font-weight: bold; margin-bottom: 20px">
    <a-breadcrumb-item>电影院管理</a-breadcrumb-item>
    <a-breadcrumb-item>用户反馈</a-breadcrumb-item>
  </a-breadcrumb>
  <a-table :columns="columns" 
  :data-source="page.list" 
  :pagination="pagination"
    @change="handleTableChange">
  </a-table>


  <a-modal v-model:visible="visible2" title="确定回复" @ok="exeReply">
    <a-form
      :model="passObj"
      :label-col="{ span: 5 }"
      :wrapper-col="{ span: 14 }"
    > 
      <a-form-item label="回复内容">
        <a-textarea v-model:value="replyObj.reply" :rows="3" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script setup>
import { ref, reactive } from "vue";
import { get, post, put, del, tip } from "@/common";
const columns = [
  {
    dataIndex: "cust_username",
    title: "评论者名称",
  },
  {
    dataIndex: "cnm_name",
    title: "电影院名称",
    sorter: (a, b) => a.cnm_com_score-b.cnm_com_score
  },
  {
    dataIndex: "com_time", //服务端数据
    title: "评论时间", //表头数据
  },
  {
    dataIndex: "com_text", //服务端数据
    title: "评论内容", //表头数据
  },
  {
    dataIndex: "cnm_com_score",
    title: "评价等级",
    sorter: (a, b) => a.cnm_com_score-b.cnm_com_score
  },
];

//分页处理-start
const query = reactive({
  "cust_username":"",
  "cnm_id":null,
  "cnm_com_score":null
}); //定义查询参数

const page = ref({}); //接收服务端返回的分页对象

//分页引擎
const pagination = reactive({
  current: 1, //当前页
  pageSize: 2, //每页记录数
  total: 0, //总记录数
  pageSizeOptions: ["2", "3", "5", "10", "20", "30", "100"], //每页记录下拉框的选型
  showSizeChanger: true, //是否展示每页记录数下拉框
  showQuickJumper: true, //是否展示快速跳转
  showTotal: (total, range) => {
    //展示总页数等文字说明信息的
    return (
      "共" +
      total +
      "条记录,当前第" +
      pagination.current +
      "页" +
      (range[1] - range[0] + 1) +
      "条记录"
    );
  },
});

//获取当前分页
const getPage = (pageNum = 1) => {
  query.pageNum = pageNum;
  query.pageSize = pagination.pageSize;

  get("/c_admin/feedback", query).then((res) => {
    page.value = res.data; //将服务端传来的分页数据赋值予page
    Screens.value = res.data.list;
    //更新分页引擎
    pagination.current = page.value.current;
    pagination.pageSize = page.value.pageSize;
    pagination.total = page.value.total;
  });
};
getPage(1); //页面加载是，首先加载第一页

//当分页发送变化时（如：页码、每页记录数变化时）
const handleTableChange = (pagi, filters, sorter, { currentDataSource }) => {
  pagination.current = pagi.current;
  pagination.pageSize = pagi.pageSize;
  pagination.total = pagi.total;

  getPage(pagination.current);
};


const replyObj = reactive({
  reply:"",
  cnm_com_id:"",
  m_id:"",
  reply_time:null
});

const visible2 = ref(false);

const openReply = (record) => {
  //打开窗口
  cnm_com_id = record.cnm_com_id;
  visible2.value = true;
};


const exeReply = () => {
  post("/c_admin/feedback",replyObj).then((res)=>{
    replyObj.reply_text="";
    replyObj.m_id="";
    visible2.value=false;
    tip.success("回复反馈成功！");
    getPage(page.value.current);
  })

};


</script>

<style scope>
</style>